#include <cstdio>
#include <vector>
#include <algorithm>


const int N = 1e3 + 9;
std::vector<int> candies[N];

/**
 * 时间复杂度：
 * 分发糖果：O(m)
 * 交换糖果：O(r)
 * 打印：O(n+m)
 * 
 * 空间复杂度：O(m)
 * 
 * 
 *交换糖果
 * @return 
 */
int main() {
    int n, m, r;
    scanf("%d %d %d", &n, &m, &r);

    for (int i = 1; i <= m; i++) {
        int x;
        scanf("%d", &x);
        candies[x].push_back(i);
    }

    while (r--) {
        int x, y;
        scanf("%d %d", &x, &y);
        if (x != y) {
            std::swap(candies[x], candies[y]);
        }
    }

    for (int i=1; i <=n; i++) {
        printf("%d ", candies[i].size());
        for (int j = 0; j < candies[i].size(); j++) {
            printf("%d ", candies[i][j]);
        }
        printf("\n");
    }
    

    return 0;
}